import { createRouter, createWebHashHistory } from 'vue-router'
import LayoutView from '@/LayoutView.vue'

const router = createRouter({
  history: createWebHashHistory(),
  routes: [
    {
      path: "/",
      redirect: "/home"
    },
    {
      path: "/",
      name: "layout",
      component: LayoutView,
      children: [
        {
          path: "/home",
          name: "home",
          component: () => import("@/views/HomeView.vue")
        },
        {
          path: "/discover",
          name: "discover",
          component: () => import("@/views/DiscoverView.vue")
        },
        {
          path: "/message",
          name: "message",
          component: () => import("@/views/MessageView.vue")
        },
        {
          path: "/user",
          name: "user",
          component: () => import("@/views/UserView.vue")
        },
        {
          path: "/favorite",
          name: "favorite",
          component: () => import("@/views/FavoriteView.vue")
        },
        {
          path: "/category",
          redirect: (to) => {
            if (to.query.cate) {
              return { path: '/discover', query: { parentCate: to.query.cate, subCate: to.query.subCate } }
            }
            return { path: '/discover' }
          }
        },
        {
          path: "/work-life",
          redirect: (to) => {
            return { path: '/discover', query: { parentCate: '工作生活' } }
          }
        },
        {
          path: "/study-more",
          redirect: (to) => {
            return { path: '/discover', query: { parentCate: '技能学习' } }
          }
        },
        {
          path: "/hobby-part",
          redirect: (to) => {
            return { path: '/discover', query: { parentCate: '兴趣爱好' } }
          }
        },
        {
          path: "/concat",
          name: "concat",
          component: () => import("@/views/ConcatView.vue")
        }
      ]
    },
    {
      path: "/login",
      name: "login",
      component: () => import("@/views/LoginView.vue")
    },
    {
      path: "/register",
      name: "register",
      component: () => import("@/views/RegisterView.vue")
    },
    {
      path: "/detail",
      name: "detail",
      component: () => import("@/views/DetailView.vue")
    },
    {
      path: "/search",
      name: "search",
      component: () => import("@/views/SearchView.vue")
    },
    {
      path: "/:pathMatch(.*)*",
      name: "error",
      component: () => import("@/views/ErrorView.vue")
    }
  ],
})

export default router
